package com.tanhua.server.controller;

import com.tanhua.server.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class    LoginController {
    @Autowired
    private Userservice userService;

    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map){
        //获得电话
        String phone =(String)map.get("phone");
        //发送验证码到手机账户
        userService.sendMsg(phone);
return ResponseEntity.ok("短信发送成功");
    }


    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map){
        //接受前端发过来的电话验证码
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");

        Map retMap = userService.loginVerification(phone,code);
        //3、构造返回
        return ResponseEntity.ok(retMap);
    }
}
